﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Jarvis.Sensors
{
    class SensorUpdate : INotifyPropertyChanged
    {
        private Sensor updateSensor;
        private object updateValue;

        public Sensor sensor
        {
            get
            {
                return this.updateSensor;
            }
            set
            {
                this.updateSensor = value;
                this.NotifyPropertyChanged("name");
            }
        }

        public object sensorValue
        {
            get
            {
                return this.updateValue;
            }
            set
            {
                this.updateValue = value;
                this.NotifyPropertyChanged("objectString");
            }
        }

        public string objectString 
        {
            get
            {
                string v = "";

                var vs = this.updateValue;

                if (vs is List<object>)
                {
                    foreach (var o in ((List<object>)vs))
                        v += o.ToString() + ", ";
                }
                else
                {
                    v = this.updateValue.ToString();
                }

                return v;
            }
        }

        public string name
        {
            get
            {
                return this.updateSensor.name;
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public SensorUpdate(Sensor sensor, object value)
        {
            this.sensorValue = value;
            this.sensor = sensor;
        }

        public void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
    }
}
